package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;

@Cmd(code = Protocol.C_UNION_KICK_PLAYER, desc = "踢出联盟")
public class CrossKickPlayerCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        UnionProto.UnionKickPlayerReqMsg reqMsg = UnionProto.UnionKickPlayerReqMsg.parseFrom(packet.getBytes());
        long kickUserId = reqMsg.getUserId();

        CrossUserBaseInfo userBaseInfo = CrossUserMgr.getCrossUserBaseInfo(packet.getPlayerId());

        ret = CrossUnionMgr.kickPlayer(userBaseInfo, kickUserId);

        UnionProto.UnionQuitRespMsg.Builder respMsg = UnionProto.UnionQuitRespMsg.newBuilder();
        respMsg.setRet(ret);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_KICK_PLAYER, respMsg));

        if(ret == GameErrorCode.E_UNION_MASTER_KICK_NUM_LIMIT){
            //到区服禁封账号
            PlayerProto.ForbidOnLinePlayerReqMsg.Builder forbidMsg = PlayerProto.ForbidOnLinePlayerReqMsg.newBuilder();
            forbidMsg.setTime(GameConfig.UNION_KICK_BAN_TIME * DateHelper.HOUR_MILLIONS);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_FORBID_ONLINE_PLAYER, forbidMsg));
        }
    }

    @Override
    public void sendData() {

    }
}
